package com.cz.modules.jxc.service.impl;

import com.cz.common.entity.BaseTree;
import com.cz.modules.jk.entity.JkCamaraEntity;
import com.cz.modules.jk.service.JkCamaraService;
import com.cz.modules.jxc.entity.JxcShopEntity;
import com.cz.modules.jxc.service.JxcShopService;
import com.cz.modules.sys.entity.SysDeptEntity;
import com.cz.modules.sys.service.SysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cz.common.utils.PageUtils;
import com.cz.common.utils.Query;

import com.cz.modules.jxc.dao.JxcCashDao;
import com.cz.modules.jxc.entity.JxcCashEntity;
import com.cz.modules.jxc.service.JxcCashService;


@Service("jxcCashService")
public class JxcCashServiceImpl extends ServiceImpl<JxcCashDao, JxcCashEntity> implements JxcCashService {
    @Autowired
    private JxcShopService jxcShopService;
    @Autowired
    private SysDeptService sysDeptService;
    @Autowired
    private JkCamaraService jkCamaraService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<JxcCashEntity> page = this.page(
                new Query<JxcCashEntity>().getPage(params),
                new QueryWrapper<JxcCashEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<BaseTree> shopTree() {
        List<BaseTree> treelist=new ArrayList<>();
        List<SysDeptEntity> deptlist=sysDeptService.list();
        List<JxcShopEntity> shoplist=jxcShopService.list();
        for (SysDeptEntity dept:deptlist) {
            if("2".equals(dept.getParentId().toString())){
                BaseTree tree=new BaseTree();
                tree.setId(dept.getDeptId().toString());
                tree.setName(dept.getName());
                tree.setParentId(dept.getParentId().toString());
                treelist.add(tree);
            }
        }
        for (JxcShopEntity shop:shoplist) {
                BaseTree tree=new BaseTree();
                tree.setId(shop.getId());
                tree.setName(shop.getShopName());
                tree.setParentId(shop.getDeptId());
                tree.setIsClick(true);
                treelist.add(tree);
        }
        return treelist;
    }



}
